package com.pureut.production.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.production.domain.ClothInspectionDetail;
import com.pureut.production.domain.dto.ClothInspectionDetailDto;
import com.pureut.production.mapper.ClothInspectionDetailMapper;
import com.pureut.production.service.ClothInspectionDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/***
 * 验布明细实现层
 * Author:C
 * Date:2023/02/20 10:57
 * @DESC
 */
@Service
public class ClothInspectionDetailServiceImpl extends ServiceImpl<ClothInspectionDetailMapper, ClothInspectionDetail> implements ClothInspectionDetailService {

    @Resource
    ClothInspectionDetailMapper clothInspectionDetailMapper;

    /**
     * 验布明细列表
     *
     * @param masterVolumeNumber
     * @return
     */
    @Override
    public List<ClothInspectionDetailDto> getList(String masterVolumeNumber) {

        List<ClothInspectionDetailDto> detailList = clothInspectionDetailMapper.getDetailList(masterVolumeNumber);
        for (ClothInspectionDetailDto entity : detailList) {
            if (entity.getStartTime() != null && entity.getEndTime() != null) {
               entity.setClothInspectionTime(getDateHour(entity.getStartTime(),entity.getEndTime()));
            }
        }
        return detailList;
    }

    /**
     * 验布明细列表 远程调用 产品追溯
     * @param masterVolumeNumber
     * @return
     */
    @Override
    public List<ClothInspectionDetailDto> selectDetailLisMasterVolumeNumber(String masterVolumeNumber) {
        List<ClothInspectionDetailDto> detailList = clothInspectionDetailMapper.getDetailList(masterVolumeNumber);
        return detailList;
    }

    public String getDateHour(Date startTime, Date endTime) {
        long time = startTime.getTime();
        long time1 = endTime.getTime();
        long a = (time1 - time) / 1000 / 60;
        double b = a/60.0;
        return String.valueOf(b);
    }
}
